/*
 * Copyright (c) 2009 Nathaniel Houghton <nathan@brainwerk.org>
 *                    Robert Kirchgessner <rkirchge@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for
 * any purpose with or without fee is hereby granted, provided that
 * the above copyright notice and this permission notice appear in all
 * copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 */

#ifndef CONFIG_HEADER
#define CONFIG_HEADER

#include <stdint.h>

#include "event.h"

/*
 * Can only store 9 parameters every half second for 8 hours 
 * (~36 bytes / sec to NVM).
 */
#define NUM_LOG_SLOTS 9


struct config {
	struct event event[NUM_LOG_SLOTS];

	/* The address we started logging at. */
	uint32_t nvm_start_addr;

#if 0
	/*
	 * Disable all logging (including to EEPROM). Useful if the
	 * device is primarily used for diagnostics.
	 */
	uint8_t logging_en;

	/*
	 * Byte set before erasing nvm, and cleared after erasing
	 * finishes. If on startup this byte is set in EEPROM, erase
	 * did not complete successfully. Can be expanded to a generic
	 * "status" byte if needed (status could be logging, erasing,
	 * etc.)
	 */
	uint8_t erasing_nvm;
#endif

	uint16_t crc;
} __attribute__((__packed__));

extern struct config cfg;

void write_config(struct config *);
int8_t read_config(struct config *);
uint8_t valid_config(struct config *);

#endif
